<?php
    $url="localhost:3306";
    $user="root";
    $password="";
    $database="php";
    $conn=mysqli_connect($url,$user,$password,$database);
    // var_dump($conn);
    if(!$conn){
        echo "error-msg:" . mysqli_connect_error();
        echo '<br>';
        echo "error-code:" . mysqli_connect_errno();
        echo '<br>';
        return;
    }
    echo "连接成功";
    echo '<br>';
    mysqli_query($conn,"set names utf8");

    $id=4;
    $name="进口考拉";
    $price=59.9;
    $unit="斤";
    $imageUrl="/day03/images/Koala.jpg";
    function updateById($id,$name,$price,$unit,$imageUrl){
        return "update product set p_name='{$name}',p_price={$price},p_unit='{$unit}',p_image_url='{$imageUrl}' where p_id={$id}";
    }
    $sql=updateById($id,$name,$price,$unit,$imageUrl);

    // 执行增删改, 成功返回true, 失败返回false。
    $result = mysqli_query($conn, $sql);
    if($result){
        echo "<div>数据更新成功</div>";
    }else{
        echo "error-msg:" . mysqli_error($conn);
    echo "<br>";
    echo "error-code:" . mysqli_errno($conn);
    echo "<br>";
    }
    mysqli_close($conn);
?>